package com.dykj.fireFighting.web.base.bigdata.controller;

import com.dykj.fireFighting.api.base.bigdata.device.service.IDeviceService;
import com.dykj.fireFighting.api.base.bigdata.device.vo.DevHisVo;
import com.dykj.fireFighting.api.base.bigdata.device.vo.DeviceVo;
import com.dykj.fireFighting.api.base.dev.service.IDevHisService;
import com.dykj.fireFighting.api.base.enterprise.entity.Enterprise;
import com.dykj.fireFighting.api.base.enterprise.service.IEnterpriseService;
import com.dykj.fireFighting.common.core.annotation.AutoLog;
import com.dykj.fireFighting.common.core.api.CommonResult;
import com.dykj.fireFighting.common.core.vo.LoginUserVo;
import com.dykj.fireFighting.web.base.shiro.ShiroUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * @Author: zly
 * @Description :
 * @Date: 2021-07-09
 */
@Slf4j
@Api(value = "大数据设备统计", tags = {"大数据设备统计"})
@RestController
@RequestMapping("bigdata/device")
public class BigDataDeviceCongroller {

    @DubboReference
    private IDeviceService iDeviceService;
    @DubboReference
    private IEnterpriseService iEnterpriseService;
    @DubboReference
    private IDevHisService devHisService;

    @AutoLog(value = "消防安全综合分析-消防统计")
    @ApiOperation(value = "消防安全综合分析-消防统计", notes = "消防安全综合分析-消防统计")
    @GetMapping("/deviceStatistics")
    public CommonResult deviceStatistics() {
        LoginUserVo user = ShiroUtil.getUser();
        HashMap<String, Object> params = new HashMap<>(16);
        Integer enterpriseType = user.getEnterpriseType();
        if (0 == enterpriseType) {
            params.put("unitId", user.getEnterpriseId().toString());
        }
        if (2 == enterpriseType) {
            List<Enterprise> enterprises = iEnterpriseService.queryUnitSelect(user.getEnterpriseId().toString());
            if (enterprises.size() > 0) {
                params.put("enterprises", enterprises);
            }
        }
        List<DeviceVo> list = iDeviceService.deviceStatistics(params);
        return CommonResult.success(list);
    }


    /**
     * 高发设备类型统计
     *
     * @param
     * @return
     */
    @AutoLog(value = "消防数据中心-高发设备类型统计")
    @ApiOperation(value = "消防数据中心-高发设备类型统计", notes = "消防数据中心-高发设备类型统计")
    @GetMapping("/queryFaultStatistical")
    public CommonResult<List<DeviceVo>> queryFaultStatistical() {
        Long enterpriseId = ShiroUtil.getUser().getEnterpriseId();
        List<DeviceVo> deviceVoList = iDeviceService.queryFaultStatistical(enterpriseId.toString());
        return CommonResult.success(deviceVoList);
    }

    /**
     * 报警趋势统计
     *
     * @param
     * @return
     */
    @AutoLog(value = "消防数据中心-报警趋势统计")
    @ApiOperation(value = "消防数据中心-报警趋势统计", notes = "消防数据中心-报警趋势统计")
    @GetMapping("/queryPoliceStatistical")
    public CommonResult<List<DevHisVo>> queryPoliceStatistical() {
        Long enterpriseId = ShiroUtil.getUser().getEnterpriseId();
        List<DevHisVo> devHisVoList = devHisService.queryPoliceStatistical(enterpriseId.toString());
        return CommonResult.success(devHisVoList);
    }

    /**
     * 高发时段统计
     *
     * @param
     * @return
     */
    @AutoLog(value = "消防数据中心-高发时段统计")
    @ApiOperation(value = "消防数据中心-高发时段统计", notes = "消防数据中心-高发时段统计")
    @GetMapping("/queryRateStatistical")
    public CommonResult<List<DevHisVo>> queryRateStatistical() {
        Long enterpriseId = ShiroUtil.getUser().getEnterpriseId();
        List<DevHisVo> deviceVoList = devHisService.queryRateStatistical(enterpriseId.toString());
        return CommonResult.success(deviceVoList);
    }

}
